//
//  DECXOrderTableViewCell2.m
//  DECXInStore
//
//  Created by 李坤 on 2019/12/10.
//  Copyright © 2019 程强. All rights reserved.
//

#import "DECXOrderTableViewCell2.h"

@interface DECXOrderTableViewCell2 ()
@property (strong, nonatomic) void(^payBlock)(void);
@property (strong, nonatomic) void(^detailsBlock)(void);
@property (strong, nonatomic) UIView *botView;
@end

@implementation DECXOrderTableViewCell2

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.contentView.backgroundColor = RGBColor(243, 244, 254);
        [self setupUI];
    }
    return self;
}
- (void)setupUI
{
    UIView *topView = [UIView new];
    topView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.width.top.equalTo(self.contentView);
        make.height.equalTo(@60);
    }];
    _orderTypeIcon = [UIButton buttonWithType:UIButtonTypeCustom];
    _orderTypeIcon.titleLabel.font = [UIFont systemFontOfSize:10.0];
    [topView addSubview:_orderTypeIcon];
    [_orderTypeIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(topView).offset(15);
        make.width.equalTo(@45);
        make.height.equalTo(@19);
        make.top.equalTo(topView).offset(5);
    }];
    _orderPayStatue = [UILabel new];
//    _orderPayStatue.text = @"待支付";
    _orderPayStatue.textAlignment = NSTextAlignmentRight;
    _orderPayStatue.font = [UIFont systemFontOfSize:13.0];
    _orderPayStatue.textColor = RGBColor(207, 75, 76);
    [topView addSubview:_orderPayStatue];
    [_orderPayStatue mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_orderTypeIcon);
        make.right.equalTo(topView).offset(-15);
        make.width.equalTo(@80);
        make.height.equalTo(@30);
    }];
    _orderTidanNo = [UILabel new];
    _orderTidanNo.text = @"提单号:29018291819872";
    _orderTidanNo.textAlignment = NSTextAlignmentLeft;
    _orderTidanNo.font = [UIFont systemFontOfSize:13.0];
    _orderTidanNo.textColor = [UIColor darkGrayColor];
    [topView addSubview:_orderTidanNo];
    [_orderTidanNo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_orderTypeIcon.mas_right).offset(5);
        make.centerY.equalTo(_orderTypeIcon);
        make.height.equalTo(@35);
        make.right.equalTo(_orderPayStatue.mas_left).offset(-10);
    }];
    _innerTime = [UILabel new];
    _innerTime.text = @"入库时间:2019-05-06";
    _innerTime.textAlignment = NSTextAlignmentLeft;
    _innerTime.font = [UIFont systemFontOfSize:12.0];
    _innerTime.textColor = [UIColor lightGrayColor];
    [topView addSubview:_innerTime];
    [_innerTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_orderTypeIcon.mas_bottom);
        make.left.equalTo(_orderTypeIcon);
        make.height.equalTo(@20);
        make.width.equalTo(@200);
    }];
    
    UIView *midView = [UIView new];
    midView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:midView];
    [midView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.width.equalTo(self.contentView);
        make.top.equalTo(topView.mas_bottom);
        make.height.equalTo(@90);
    }];
    _productLogo = [UIImageView new];
    [midView addSubview:_productLogo];
    [_productLogo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.equalTo(@60);
        make.centerY.equalTo(midView);
        make.left.equalTo(midView).offset(10);
    }];
    _orderName = [UILabel new];
    _orderName.text = @"精品多哥白芝麻";
    _orderName.textAlignment = NSTextAlignmentLeft;
    _orderName.font = [UIFont systemFontOfSize:13.0];
    [midView addSubview:_orderName];
    [_orderName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_productLogo);
        make.height.equalTo(@25);
        make.left.equalTo(_productLogo.mas_right).offset(10);
        make.right.equalTo(midView).offset(-100);
    }];
    _orderWeight = [UILabel new];
    _orderWeight.text = @"剩余重量:100吨";
    _orderWeight.textAlignment = NSTextAlignmentLeft;
    _orderWeight.font = [UIFont systemFontOfSize:13.0];
    [midView addSubview:_orderWeight];
    [_orderWeight mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_orderName);
        make.top.equalTo(_orderName.mas_bottom).offset(5);
        make.height.equalTo(@25);
        make.width.equalTo(@200);
    }];
    
    UIView *bottomView = [UIView new];
    bottomView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:bottomView];
    self.botView = bottomView;
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(midView.mas_bottom);
        make.centerX.width.equalTo(self.contentView);
        make.bottom.equalTo(self.contentView).offset(-10);
    }];
//    _sumMoney = [UILabel new];
//    _sumMoney.textAlignment = NSTextAlignmentRight;
//    _sumMoney.font = [UIFont systemFontOfSize:13.0];
//    _sumMoney.text = @"合计：￥250000";
//    [bottomView addSubview:_sumMoney];
//    [_sumMoney mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.equalTo(bottomView).offset(-15);
//        make.height.equalTo(@30);
//        make.left.equalTo(bottomView).offset(15);
//        make.top.equalTo(bottomView).offset(5);
//    }];
    _payBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_payBtn setTitle:@"提货" forState:UIControlStateNormal];
    [_payBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    _payBtn.titleLabel.font = [UIFont systemFontOfSize:13.0];
    [_payBtn setBackgroundImage:LoadImage(@"pay_btn") forState:UIControlStateNormal];
    [_payBtn addTarget:self action:@selector(payClick) forControlEvents:UIControlEventTouchUpInside];
    [bottomView addSubview:_payBtn];
    [_payBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@76);
        make.height.equalTo(@32);
        make.right.equalTo(bottomView).offset(-15);
        make.centerY.equalTo(bottomView);
    }];
    _detailsBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_detailsBtn setTitle:@"费用明细" forState:UIControlStateNormal];
    [_detailsBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    _detailsBtn.titleLabel.font = [UIFont systemFontOfSize:13.0];
    [_detailsBtn setBackgroundImage:LoadImage(@"pay_btn") forState:UIControlStateNormal];
    [_detailsBtn addTarget:self action:@selector(detailsClick) forControlEvents:UIControlEventTouchUpInside];
    [bottomView addSubview:_detailsBtn];
    [_detailsBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@76);
        make.height.equalTo(@32);
        make.right.equalTo(self.contentView).offset(-105);
        make.centerY.equalTo(bottomView);
    }];
    
    _reviewIcon = [UIImageView new];
    [topView addSubview:_reviewIcon];
    [_reviewIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@62);
        make.height.equalTo(@44);
        make.centerY.equalTo(topView);
        make.right.equalTo(topView).offset(-20);
    }];
}
- (void)setHiddenDeliveryBtn:(BOOL)hiddenDeliveryBtn
{
    _hiddenDeliveryBtn = hiddenDeliveryBtn;
    if (hiddenDeliveryBtn) {
        _payBtn.hidden = YES;
        [_detailsBtn mas_updateConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-15);
        }];
    }else{
        _payBtn.hidden = NO;
        [_detailsBtn mas_updateConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-105);
        }];
    }
}
- (void)setOrderInfo:(DECXStoreOrder *)order
{
    self.orderTidanNo.text = [NSString stringWithFormat:@"提单号:%@",order.getlist_id];
    self.innerTime.text = [NSString stringWithFormat:@"入库时间:%@",order.time];
    [self.productLogo setImageWithURL:[NSURL URLWithString:order.pic] placeholderImage:LoadImage(@"place_image")];
    self.orderName.text = order.name;
    self.orderWeight.text = [NSString stringWithFormat:@"剩余重量:%@吨",order.weight];
    if ([order.state isEqualToString:@"0"]) {
        self.reviewIcon.image = LoadImage(@"review_wait");
        self.botView.hidden = YES;
    }else if ([order.state isEqualToString:@"1"]){
        self.reviewIcon.image = LoadImage(@"review_success");
        self.botView.hidden = NO;
    }else if ([order.state isEqualToString:@"2"]){
        self.reviewIcon.image = LoadImage(@"review_failure");
        self.botView.hidden = YES;
    }
    if ([order.type integerValue] == 1) {
        [self.orderTypeIcon setTitle:@"合约仓单" forState:UIControlStateNormal];
        [self.orderTypeIcon setBackgroundImage:LoadImage(@"heyue_cangdan") forState:UIControlStateNormal];
    }else if ([order.type integerValue] == 2){
        [self.orderTypeIcon setTitle:@"普通仓单" forState:UIControlStateNormal];
        [self.orderTypeIcon setBackgroundImage:LoadImage(@"putong_cangdan") forState:UIControlStateNormal];
    }
}
- (void)payClick
{
    if (self.payBlock) {
        self.payBlock();
    }
}
- (void)payOrderClickHandler:(void(^)(void))block
{
    self.payBlock = block;
}
- (void)detailsClick
{
    if (self.detailsBlock) {
        self.detailsBlock();
    }
}
- (void)chargeDetailsClickHandler:(void(^)(void))block
{
    self.detailsBlock = block;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
